# Copyright 1999-2010 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: games-arcade/frogatto/frogatto-1.0.ebuild frostwork Exp $

EAPI="3"

#inherit eutils games flag-o-matic toolchain-funcs
inherit eutils games flag-o-matic

DESCRIPTION="a frog, and a platform game"
HOMEPAGE="http://frogatto.com/"
SRC_URI="https://github.com/frogatto/frogatto/tarball/${PV}_stable -> ${P}.tar.gz"

LICENSE="GPL-3 free-noncomm"
SLOT="0"
KEYWORDS="~amd64 ~x86"
IUSE=""

IUSE_MODULES="aritest cube_trains elisa hex secluded-isle tictactoe vgi wip_levels cellular duxduo frogatto rpg stellar_limit tileciv weregild"

DEPEND="media-libs/sdl-image
        media-libs/libsdl
        media-libs/sdl-mixer
        media-libs/sdl-ttf
        media-libs/glew
        dev-libs/boost
        virtual/opengl
        virtual/glu"

for module in ${IUSE_MODULES} ; do
    IUSE+=" frogatto_modules_${module}"
done
unset module

src_unpack() {
    unpack ${A}
    mv ${WORKDIR}/${PN}-${PN}* ${WORKDIR}/${P}
    S=${WORKDIR}/${P}
}

src_prepare() {
    epatch "${FILESDIR}"/${P}-libpng.patch || die
}

src_compile() {
    emake USE_CCACHE="no" || die
}

src_install() {
    newgamesbin "${FILESDIR}"/${PN} ${PN}
    insinto "${GAMES_DATADIR}"/${PN}
    doins -r data images music *.ttf || die

    insinto "${GAMES_DATADIR}"/${PN}/modules
    doins -r modules/frogatto || die

    for x in ${IUSE_MODULES} ; do
        if has ${x} ${FROGATTO_MODULES}; then
            doins -r modules/${x} || die
        fi
    done

    exeinto "${GAMES_DATADIR}"/${PN}
    doexe game
    newicon images/window-icon.png ${PN}.png
    make_desktop_entry ${PN}
    prepgamesdirs
}

pkg_postinst() {
    elog
    elog "To install addition modules you must add next changes to /etc/make.conf:"
    elog "1. add line"
    elog "\`USE_EXPAND=\"\${USE_EXPAND} FROGATTO_MODULES\"\`"
    elog
    elog "2. define list of required modules in FROGATTO_MODULES variable like this:"
    elog "\`FROGATTO_MODULES=\"cube_trains duxduo\"\`"
    elog
}
